<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<div>
  <h1>商品列表</h1>
    <table border="1">
        <tr>
            <th>序号</th><th>标题</th><th>价格</th><th>库存</th><th>操作</th>
        </tr>
        <tr v-for="(p,i) in products">
            <td>{{i+1}}</td>
            <td>{{p.title}}</td>
            <td>{{p.price}}</td>
            <td>{{p.num}}</td>
            <td>
                <a :href="'/update.html?id='+p.id" >修改</a>
                <a href="javascript:void(0)" @click="del(p.id)">删除</a>
                <!--<input type="button" value="删除" @click="del(p.id)">-->
                <!--<input type="button" value="修改" @click="update(p.id)">-->
            </td>
        </tr>
    </table>
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<script>
  let v = new Vue({
    el:"body>div",
    data:{
      products:[]
    },
    methods:{
      del(id){
          if(confirm("您确认删除此商品吗？")){
              /*axios.post("/delete",{id:id}).then(function (response) {*/
              axios.post("/delete?id="+id).then(function (response) {
                  switch (response.data) {
                      case 1 : alert("删除成功");break;
                      default : alert("删除失败");break;
                  }
                  location.reload();
              })
          }
      }
    },
    created:function (){
        axios.get("/select").then(function (response) {
            v.products = response.data;
        })
    }

  })
</script>
</body>
</html>